﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.Member;
using Jzy.Core.Common;
using Jzy.Core.Common.Web;
using Jzy.Model.Member;
using Jzy.BLL.Forum;
using Jzy.Model.Forum;
using Jzy.Core.Common.Basic;
using Jzy.Core.Utility;

namespace Jzy.Web.Forum.Member
{
    public partial class List : PageList
    {
        private ForumMemberBO Member
        {
            get
            {
                return ForumMemberBO.Instance<ForumMemberBO>();
            }
        }
        private PagerSortSetting _setting;
        protected void Page_Load(object sender, EventArgs e)
        {
            _setting = this.Footer1.InitPager(new BindViewHandler(BindView));
            if (!IsPostBack)
            {
                
                BindView();
            }
            AddAttr();
        }

        private void AddAttr()
        {
            base.ShowForm(lnkAdd, "增加会员", GlobalVar.WebCurrPath + "Edit.aspx", 450, 360);
        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            string condition = " 1=1";
            if (txtLoginName.Text.Trim() != "")
            {
                condition += " and LoginName like '%" + txtLoginName.Text.Trim() + "%'";
            }
            if (txtName.Text.Trim() != "")
            {
                condition += " and Name like '%" + txtName.Text.Trim() + "%'";
            }
            if (txtMobile.Text.Trim() != "")
            {
                condition += " and Moblie like '%" + txtMobile.Text.Trim() + "%'";
            }
            if (txtEmail.Text.Trim() != "")
            {
                condition += " and Email like '%" + txtEmail.Text.Trim() + "%'";
            }
            _setting.SortExpression = "RegisterTime";
            _setting.SortDirection = Jzy.Core.Common.SortDirection.desc;
            //_setting.PageSize = 20;

            IEnumerable<ForumMemberInfo> list = this.Member.GetList(_setting, condition);

            lv.DataSource = list;
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataBind();

            lblStatistic.Text = "会员列表&nbsp;[&nbsp;共&nbsp;" + _setting.RecordCount + "&nbsp;个&nbsp;]";
        }

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {              
                HyperLink lnkEdit = (HyperLink)e.Item.FindControl("lnkEdit");               

                string strID = StrUtil.EncryptUrl(lv.DataKeys[((ListViewDataItem)e.Item).DataItemIndex]["ID"].ToString());

                JSUtil.ShowForm(lnkEdit, "修改用户信息", null, GlobalVar.WebCurrPath + "Edit.aspx?ID=" + strID, 450, 360);

            }
        }

        protected void btnSerch_Click(object sender, EventArgs e)
        {
            BindView();
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs == "")
            {
                return;
            }
            this.Member.Delete(strSelectIDs, true);
            BindView();
        }
    }
}
